<script>
init({
  title: 'Fixed Scroll',
  desc: 'Set `true` to enable the fixed scrollbar position of the table when loading data.',
  links: ['bootstrap-table.min.css'],
  scripts: ['bootstrap-table.min.js']
})
</script>

<template>
  <div id="toolbar">
    <button
      id="button"
      class="btn btn-secondary"
    >
      load
    </button>
  </div>
  <table
    id="table"
    data-toggle="table"
    data-toolbar="#toolbar"
    data-height="460"
    data-fixed-scroll="true"
    data-url="json/data1.json"
  >
    <thead>
      <tr>
        <th data-field="id">
          ID
        </th>
        <th data-field="name">
          Item Name
        </th>
        <th data-field="price">
          Item Price
        </th>
      </tr>
    </thead>
  </table>
</template>

<script>
  const $table = $('#table')
  const $button = $('#button')

  function randomData () {
    const startId = ~~(Math.random() * 100)
    const rows = []

    for (let i = 0; i < 21; i++) {
      rows.push({
        id: startId + i,
        name: `test${startId + i}`,
        price: `$${startId + i}`
      })
    }
    return rows
  }

  function mounted () {
    $button.click(function () {
      $table.bootstrapTable('load', randomData())
    })
  }
</script>
